package qgs.zisu.javaconcurrency.javaconcurrency.chapter3_createThread;

/**
 * @Author: 蔡翔
 * @Date: 2019/9/12 10:00
 * @Version 1.0
 */
public class CreateThread2 {
    public static void main(String[] args) {
        Thread thread = new Thread(){
            @Override
            public void run(){
                try {
                    Thread.sleep(100);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        };
        thread.start();
        //thread.getThreadGroup();  //如果我现在的thread 没有ThreadGroup ，那么就把我父级的ThreadGroup 给返回你。

        /*System.out.println(Thread.currentThread().getName()); //如果不start ，那么 当前线程是main
        System.out.println(Thread.currentThread().getThreadGroup().getName());
        */
        ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
        System.out.println("线程组名字："+threadGroup.getName());
        System.out.println("线程组里面线程数量："+threadGroup.activeCount());

        Thread[] threads = new Thread[threadGroup.activeCount()];
        threadGroup.enumerate(threads);   //去枚举线程

        for(Thread thread1 : threads){
            System.out.println(thread1);
        }

        // java 1.8 新特性。
        //Arrays.asList(threads).forEach(System.out::println);

    }
}
